<?php

class Admini_ManagemystoreController extends Uuch_ManageController{
    
    public function init() {
        parent::init();
        $this->appendCss('/css/Share.css');//    
        $this->appendCss('/css/home/warehouse.css');
        //$this->_helper->layout->setLayout('admin');
        $this->appendScript('/admins/js/jquery/jquery-1.7.2.min.js')->appendScript('/js/jquery.validate.min.js')->appendScript('/js/messages_cn.js')->appendScript('/js/uuch.js');      
    }

    public function indexAction() {
        $count = 7;
        $start = $this->_getParam('start');
        
        //查询条件
        $username = $this->_getParam('username');
        $storeno = $this->_getParam('storeno');
        $orderno = $this->_getParam('orderno');
        $dateinbegin = $this->_getParam('dateinbegin');
        $dateinend = $this->_getParam('dateinend');
        
        if(!$start)
        {
            $start=0;
        }

        $this->view->StoreItem = Application_Model_StoreItem::getMyByFilter($username, $storeno, $orderno, $dateinbegin, $dateinend, $count, $start);      
        $this->view->StoreItemList = $this->view->StoreItem['list'];
    }


    /**
     * 预报入库管理
     */
    public function ingstoreAction() {
        $count = 10;
        $start = $this->_getParam('start');
        //查询条件
        $username = $this->_getParam('username');
        $state = $this->_getParam('state');
        $orderno = $this->_getParam('orderno');
        $dateinbegin = $this->_getParam('dateinbegin');
        $dateinend = $this->_getParam('dateinend');

        if (!$start) {
            $start = 0;
        }
        
        $this->view->IngstoreItem = Application_Model_ingstore::getMyByFilter($username, $state, $orderno, $dateinbegin, $dateinend, $count, $start);
        $this->view->IngstoreItemList = $this->view->IngstoreItem['list'];
    }

    /**
     * 包裹入库
     */
    public function instoreAction() {
        echo 123;exit;
//        $this->appendScript('/js/jquery.validate.min.js')->appendScript('/js/messages_cn.js');

//        if ((int) $this->_getParam('id') > 0) {
//            //预报入库管理验货入库传过来的ID，加载storeItem对象
//            $ingstoreItem = Application_Model_ingstore::load($this->_getParam('id'));
//            $this->view->ingstoreItem = $ingstoreItem;
//        }
//
//        if ($this->getRequest()->isPost()) {
//            $item = new Application_Model_StoreItem();
//            $item->ProductName = $this->_getParam('productName');
//            $item->StoreId = $this->_getParam('storeId');
//            $item->DateInStore = $this->now();
//            $item->Quantity = 1;
//            $item->State = Application_Model_StoreItem::STATUS_InStored;
//            $item->Logisticsname = $this->_getParam('logisticName');
//            $item->Logistics = '[' . $item->Logisticsname . ']' . $this->_getParam('logistics');
//            $item->OrderNo = $item->Logistics;
//            $item->Userid = $this->_getParam('userid');
//            $item->Weight = $this->_getParam('weight');
//            $item->Length = $this->_getParam('length');
//            $item->Width = $this->_getParam('width');
//            $item->Height = $this->_getParam('height');
//            $item->Createdate = $this->now();
//            $item->IsPack = $this->_getParam('isPack');
//            $item->BignessType = $this->_getParam('bignessType');
//            $item->VolumeWeight = $this->_getParam('volumeWeight');
//            $item->CanVacuum = $this->_getParam('canVacuum');
//            $item->VacuumWeight = $this->_getParam('vacuumWeight');
//            $item->NoPackageWeight = $this->_getParam('noPackageWeight');
//            $item->IsEmbargo = $this->_getParam('isEmbargo');
//            $item->Barcode = $this->_getParam('barcode');
//            $item->Image = $this->_getParam('image');
//            $item->ItemType = $this->_getParam('itemType');
//            if ($item->ItemType == NULL) {
//                $item->ItemType = 0;
//            }
//
//            //如果产品类型选择了仿牌，则设置是否仿牌为1；否则设置为0
//            if ($item->ItemType == 1) {
//                $item->IsBrand = 1;
//            } else {
//                $item->IsBrand = 0;
//            }
//
//            $item->save();
//
//            if ($this->_getParam('ingstoreId')) {
//                $ingstoreItem = Application_Model_ingstore::load($this->_getParam('ingstoreId'));
//                if ($ingstoreItem) {
//                    $ingstoreItem->state = '1';
//                    $ingstoreItem->save();
//                }
//            }
//            $this->content('<a href="/managestore/index">入库成功，查看用户仓库</a>');
//        }
//        $brcode = date("ymd") . substr(time(), -5, 5);
//        echo $brcode;exit;
//        $barcode = new Uuch_BarCode128($brcode,$brcode);
////        $barcodeimg = $barcode->createBarCode();
//        $barcode->createBarCode();exit;
//        $this->view->barcodeimg = $barcodeimg;
//        echo $barcodeimg;exit;
    }

    /**
     * 根据仓库号，获取用户信息
     * @return type
     */
    public function userinfoAction() {
        $user = Application_Model_User::getByStoreNo($this->_getParam('storeno'));

        if ($user == null) {
            $this->json(0);
            return;
        }
        $this->json(array('userid' => $user->Id, 'email' => $user->Email, 'nikeName' => $user->Nikename));
    }
}